package com.youthfilmic.yuejian.util;

import com.aliyun.oss.OSS;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

/**
 * Created by youweixi on 15/9/18.
 */
public class SaveImageFromUrlThread implements Runnable {
    private String imageUrl;
    private String path;
    private String resultUrl;
    public SaveImageFromUrlThread(String imageUrl , String path){
        this.imageUrl = imageUrl;
        this.path = path;
        this.resultUrl = OSSUtil.imageServer + path;
    }

    public String getResultUrl(){
        return resultUrl;
    }

    @Override
    public void run() {
        try {
            OSSUtil.saveImage(imageUrl , path);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 获取随机文件名
     * */
    public static String getRamdomName(){
        return new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()) + String.format("%03d", new Random().nextInt(999));
    }

    public static void main(String[] args){
        //用法
//        SaveImageFromUrlThread thread2 = new SaveImageFromUrlThread(this.imageLarge,"book_covers/large/" + isbn13 + ".jpg");
//        this.imageLarge = thread2.getResultUrl();
//        SpringThreadPool.addThread(new Thread(thread1));
    }
}
